<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<title>dijit/Tree with dojox/data/JsonRestStore automated test</title>

	<script type="text/javascript" src="../boilerplate.js"></script>

	<script type="text/javascript">
		require([
			"doh/runner",
			"dojo/dom",
			"dojo/on",
			"dijit/Tree",
			"dijit/tree/ForestStoreModel",
			"dijit/tree/dndSource",
			"dojox/data/JsonRestStore",
			"dojo/domReady!"
		], function(doh, dom, on, Tree, ForestStoreModel, dndSource, JsonRestStore){

			var myTree;

			doh.register("Tree with dojox/data/JsonRestStore test", [
				{
					timeout: 3000,
					name: "create",
					runTest: function(){
						var
							d = new doh.Deferred(),
							myStore = new JsonRestStore({target:"./", labelAttribute:"name"}),
							myModel = new ForestStoreModel({
								store: myStore,
								deferItemLoadingUntilExpand: true,
								query: "treeTestRoot",
								childrenAttrs: ["children"]
							});
						myTree = new Tree({
							id: "myTree",
							model: myModel,
							label: "Example",
							persist: false,		// persist==true is too hard to test
							dndController: "dijit.tree.dndSource" 
						});
						doh.t(myTree, "tree created");

						dom.byId("container").appendChild(myTree.domNode);
						myTree.startup();
						myTree.onLoadDeferred.then(d.getTestCallback(function(){
							// Give the tree time to load, and the do checks that it
							// loaded correctly
							doh.t(myTree.rootNode, "root node exists");
							doh.t(myTree.rootNode.isExpanded, "root node is expanded");

							var children = myTree.rootNode.getChildren();
							doh.is(5, children.length, "six children");
							doh.is("node1", children[0].label, "first child");
							doh.f(children[0].isExpanded, "first child not expanded");
						}));
						return d;
					}
				},
				{
					timeout: 2000,
					name: "open a node",
					runTest: function(){
						var d = new doh.Deferred(),
							first = myTree.rootNode.getChildren()[0];

						on.emit(first.expandoNode, "click", {bubbles: true});

						setTimeout(d.getTestErrback(function(){
							var firstFirst = first.getChildren()[0];
							on.emit(firstFirst.expandoNode, "click", {bubbles: true});
							setTimeout(d.getTestCallback(function(){
								var children = firstFirst.getChildren();
								doh.is(2, children.length, "two children");
								doh.is("node1.1.1", children[0].label, "first child");
							}), 750);
						}), 750);

						return d;
					}
				}
			]);

			doh.run();
		});
	</script>

</head>
<body class="claro" role="main">
	<h1 class="testTitle">dijit/Tree with dojox/data/JsonRestStore automated test</h1>
	<div id="container"> <!--  tree will go here --></div>
	<div id="container2"> <!--  tree2 will go here --></div>
</body>
</html>
